<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title th:text="#{withdrawpage.title}"></title>
        <meta name="description" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
        
        <!--[if lte IE 9]><link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" /><![endif]-->

		<link rel="stylesheet" href="css/css.css" th:href="@{/css/min.css}"/>            
        <script src="http://lib.sinaapp.com/js/jquery/1.9.0/jquery.min.js" th:src="@{http://lib.sinaapp.com/js/jquery/1.9.0/jquery.min.js}"></script>
        <script th:inline="javascript">/*<![CDATA[*/
        window.jQuery || document.write('<script src="'+ /*[[@{/js/vendor/jquery-1.9.0.min.js}]]*/ 'js/vendor/jquery-1.9.0.min.js'
        		+'"><\/script>')
        /*]]>*/</script>
        <script type="text/javascript" th:src="@{/js/econgen.js}"></script>
        <script type="text/javascript" th:inline="javascript">/*<![CDATA[*/
			var x = /*[[${session.session_user.bank}]]*/ ;
			if(!x){
				alert(/*[[#{withdrawpage.js.bankinfofirst}]]*/''
					);
				location.assign(/*[[@{/i/bank.html}]]*/'./bank.html'
        		);
			}
			$(function(){
				
				
				$('#confirm').bind('click', function(){
					var withDrawNum = $('#withDraw').val();
					if(isNaN(withDrawNum) || withDrawNum < 1){
						alert(/*[[#{withdrawpage.js.withdrawnumvalid}]]*/''
							);
						return;
					}
					$.ajax({
						url: /*[[@{/i/canWithDraw}]]*/'./canWithDraw'
						, type: 'GET'
       					, dataType: 'json'
       					, error: function(jqXHR, textStatus, errorThrown){
       						alert(/*[[#{withdrawpage.js.withdrawnoenough}]]*/''
       							);
       					}
						, success: function(data, textStatus, jqXHR){
							if(!data || isNaN(data)){
								alert(/*[[#{withdrawpage.js.withdrawnotconfirmed}]]*/''
									);
								return;
							}
							if(data < withDrawNum){
								alert(/*[[#{withdrawpage.js.withdrawfailednoenough}]]*/''
									);
								return;
							}
							$.ajax({
								url: /*[[@{/i/withDraw}]]*/'./withDraw'
								, type: 'POST'
								, dataType: 'json'
								, data: {
									withDraw: withDrawNum
								}
								, error: function(jqXHR, textStatus, errorThrown){
									alert(jqXHR);
								}
								, success: function(data, textStatus, jqXHR){
									if(data && data.result == 1){
										alert(/*[[#{withdrawpage.js.withdrawsubmitted}]]*/''
											);
										return;
									}
									alert(/*[[#{withdrawpage.js.withdrawfailed}]]*/''
										);
								}
							});
						}
					});
				});
			});
        /*]]>*/</script>
    </head>
    <body>
        <header th:substituteby="common/template::header"></header>
        
        <div class="container">
        	<div class="row">
        		<h1 th:text="#{withdrawpage.content.title}"></h1>
        	</div>
        	<hr/>
        	<div class="row">
        		<div class="ninecol">
        			<ul id="bankInfo">
        				<li>
        					<label th:text="#{withdrawpage.content.canwithdraw}"></label>
        					<span th:text="(${session.session_user.totalBalance}?${session.session_user.totalBalance}:0) - (${session.session_user.withDrawing}?${session.session_user.withDrawing}:0)"></span>
        				</li>
        				<li>
        					<label th:text="#{withdrawpage.content.withdraw}"></label>
        					<input id="withDraw" value="0"/>
        				</li>
        			</ul>
        		</div>
        		<div class="threecol last">
        			<p>
	        			<button id="confirm" class="form-btn"><i class="icon-checkmark"></i><span th:text="#{withdrawpage.content.dowithdraw}"></span></button>
        			</p>
        			<p>
	        			<a class="form-btn" th:href="@{/i}"><i class="icon-close"></i><span th:text="#{withdrawpage.content.cancelwithdraw}"></span></a>
        			</p>
        		</div>
        	</div>
        </div>

        <footer th:substituteby="common/template::footer"></footer>
        
    </body>
</html>
